package com.example.testhooter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;

import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class CategoryActivity extends Activity {
 
	static final String CAT_ID = "cat_id";
	static final String CAT_NAME = "cat_name";	
	
	ListView cat_list;
	BindCategoryData adapter = null;
	List<HashMap<String, String>> categoryDataCollection;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_category);
		
		categoryDataCollection = new ArrayList<HashMap<String,String>>();
		HashMap<String,String> map = null;
		map = new HashMap<String,String>();
		map.put(CAT_ID, "1");
		map.put(CAT_NAME, "ABC");
		categoryDataCollection.add(map);
		map = new HashMap<String,String>();
		map.put(CAT_ID, "2");
		map.put(CAT_NAME, "DEF");
		categoryDataCollection.add(map);

		BindCategoryData bindingData = new BindCategoryData(this, categoryDataCollection);
		cat_list = (ListView) findViewById(R.id.list);		
		cat_list.setAdapter(bindingData);		
 
		cat_list.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent i = new Intent();
				i.setClass(CategoryActivity.this, SubCategoryActivity.class);
				// parameters
				i.putExtra("position", String.valueOf(position + 1));				
				i.putExtra("cat_id",
						categoryDataCollection.get(position).get(CAT_ID));
				i.putExtra("cat_name",
						categoryDataCollection.get(position).get(CAT_NAME));
				
				startActivity(i);
			}
		});
	}

}
